package com.teach.controller;

import com.teach.dto.CourseSection;
import com.teach.entity.ResponseEntity;
import com.teach.service.TbCourseSectionService;
import com.teach.utils.ALiBaBaOSS;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/courseSection")
@Api(tags = "课程章节的controller")
public class CourseSectionController {
    @Resource
    TbCourseSectionService tbCourseSectionService;

    @PostMapping("/list")
    @ApiOperation("课程章节的列表")
    public ResponseEntity getAll(@RequestBody CourseSection courseSection){
        System.out.println("666666");
        return tbCourseSectionService.getAll(courseSection);
    }

    @PostMapping("/sectionAdd")
    @ApiOperation("课程章节的添加")
    public ResponseEntity sectionAdd(@RequestBody CourseSection courseSection, HttpServletRequest request){
        String token = request.getHeader("token");
        return tbCourseSectionService.sectionAdd(courseSection,token);
    }

    @GetMapping("/delById")
    @ApiOperation("课程章节的删除")
    public ResponseEntity delById(@RequestParam(value = "id")Integer id,HttpServletRequest request){
        String token = request.getHeader("token");
        return tbCourseSectionService.delById(id,token);
    }

    @GetMapping("/findById")
    @ApiOperation("课程章节的回显")
    public ResponseEntity findById(@RequestParam(value = "id")Integer id){
        return tbCourseSectionService.findById(id);
    }

    @PostMapping("/updateSecation")
    @ApiOperation("课程章节的修改")
    public ResponseEntity updateSecation(@RequestBody CourseSection courseSection,HttpServletRequest request){
        String token = request.getHeader("token");
        return tbCourseSectionService.updateSecation(courseSection,token);
    }

    @PostMapping("/imagesFile")
    @ApiOperation("图片视频上传")
    public String imagesFile(@RequestPart(value = "file")MultipartFile file){
        String url=null;
        try {
            url = ALiBaBaOSS.uploadFileByStreamPublic(file);
        }catch (Exception e){
            e.printStackTrace();
        }
        return url;
    }

}
